package 牛客剑指专题二刷.链表;

/**
 * author:JiangSong
 * Date:2023/7/3
 **/

/**
 * 反转链表
 法1：遍历，数组，新建链表
 法2：遍历中处理,双指针
 */

public class JZ24 {
    class ListNode{
        int val;
        ListNode next = null;
        ListNode(int val){
            this.val = val;
        }
    }

    public ListNode ReverseList (ListNode head) {
        // write code here
        ListNode pre = null, cur = head;
        while(cur != null){
            ListNode t = cur;
            cur = cur.next;
            t.next = pre;
            pre = t;
        }
        return pre;
    }
}
